package com.solution.framework.util;

import org.apache.commons.codec.digest.DigestUtils;

import java.io.UnsupportedEncodingException;

/**
 * Created with IntelliJ IDEA.
 * User: sunguangzhu
 * Date: 14-4-16
 * Time: 下午4:48
 * To change this template use File | Settings | File Templates.
 */
public class MD5Utils {

    public static boolean validateMD5Info(String content, String md5) {
        boolean flag = false;
        //ISO-8859-1
        String s = null;
        try {
            s = DigestUtils.md5Hex(content.getBytes("ISO-8859-1"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        if (md5.equals(s)) {
            flag = true;
        }
        return flag;
    }

    public static String encrype(String content) {
        try {
            content = DigestUtils.md5Hex(content.getBytes("ISO-8859-1"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return content;
    }
}
